package logmanager.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JMenuItem;

import logmanager.openfiles.OpenFilesView;
import logmanager.view.Principal;
import logmanager.view_properties.PropertiesView;


public class ActionMenuCliked implements ActionListener{
	public Principal p;

	public ActionMenuCliked(Principal p) {
		super();
		this.p = p;
	}

	public void actionPerformed(ActionEvent e) {
		JMenuItem item=(JMenuItem)e.getSource();
		if(item.getText()=="Ouvrir"){
			try {
				OpenFilesView opfv = new OpenFilesView(p, p.logManager.getFiles());
				opfv.showZDialog();
			} catch (RemoteException e1) {
				e1.printStackTrace();
			}
		}else if(item.getText()=="Deconnecter")
			p.disconnect();
		else if(item.getText()=="Quitter"){
			if(!p.disconnected)
				p.disconnect();
			System.exit(0);
		}else if(item.getText()=="Fermer"){
			int pos = p.pv.tables.getSelectedIndex();
			p.pv.closeLog(pos);
			if(p.pv.tables.getTabCount() != 0)
				p.setSelectedIndex(p.pv.tables.getSelectedIndex());
		}else if(item.getText()=="Fermer tous"){
			p.pv.closeAllLog();
		}else if(item.getText()=="Propriete"){
			PropertiesView pv = new PropertiesView(p);
			pv.showZDialog();
		}
	}

}
